﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SmartSpace.Web;

namespace SmartSpace.News.UI.Pages
{
    public partial class CreateAsset : System.Web.UI.Page
    {
        private Guid _categoryId { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            _categoryId = Guid.Parse(Request.QueryString["assets_category_id"]);
        }

        protected void _ctlBtnSave_Click(object sender, EventArgs e)
        {
            AssetService service = new AssetService(); 

            Asset asset = new Asset();
            asset.Id = Guid.NewGuid();
            asset.Code = _ctrlCode.Text;
            asset.CategoryId = _categoryId;
            asset.Keeper = _ctrlKeeper.Text;
            asset.Name = _ctrlName.Text;
            asset.Price = Convert.ToDouble(_ctrlPrice.Text);
            asset.Creator = Page.User.Identity.Name;
            asset.CreateDate = DateTime.Now;
            asset.GuaranteeDate = Convert.ToDateTime(_ctrlGuaranteeDate.Text);
            asset.Remark = _ctrlRemark.Text;
            asset.SerialNo = _ctrlSerialNo.Text;
            asset.Specification = _ctrlSpecification.Text;
            asset.Status = AssetStatus.Unused;
            service.SaveAsset(asset);

            SsPage.Return(this, new { id = asset.Id });
        }
    }
}